package com.foreverwin.jzymes.common.service.impl;

import com.foreverwin.jzymes.common.mapper.NCGroupAdviceMapper;
import com.foreverwin.jzymes.common.service.INCGroupAdviceService;
import com.foreverwin.jzymes.common.util.BOHandleUtil;
import com.foreverwin.jzymes.framework.util.I18nUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.Assert;

import java.util.List;
import java.util.Map;

@Service
public class NCGroupAdviceServiceImpl implements INCGroupAdviceService {
    @Autowired
    NCGroupAdviceMapper ncGroupAdviceMapper;

    /**
     * 查询不合格代码组
     *
     * @param site
     * @param ncGroup
     * @return
     */
    public Map<String,Object> findNCGroup( String site, String ncGroup ){
        Assert.hasText( site, I18nUtil.getI18nText( "common.siteNotBlank" ) );
        Assert.hasText( ncGroup, I18nUtil.getI18nText( "common.ncGroupNotBlank" ) );

        return ncGroupAdviceMapper.selectNCGroup( site, ncGroup );
    }

    /**
     * 查询不合格代码组是否存在
     *
     * @param site
     * @param ncGroup
     * @return
     */
    public Map<String,Object> existNCGroup( String site, String ncGroup ){
        Map<String,Object> ncGroupMap = findNCGroup( site, ncGroup );

        Assert.isTrue( ncGroupMap != null, I18nUtil.getI18nText( "common.ncGroupNotExist", new Object[]{ ncGroup } ) );
        return ncGroupMap;
    }

    /**
     * 查询不合格代码组不合格代码
     *
     * @param site
     * @param ncGroup
     * @return
     */
    public List<Map<String,Object>> findNCGroupMember( String site, String ncGroup ){
        Assert.hasText( site, I18nUtil.getI18nText( "common.siteNotBlank" ) );
        Assert.hasText( ncGroup, I18nUtil.getI18nText( "common.ncGroupNotBlank" ) );
        String ncGroupBo = BOHandleUtil.buildNcGroupHandle( site, ncGroup );

        return ncGroupAdviceMapper.selectNCGroupMember( ncGroupBo );
    }

    /**
     * 查询不合格代码组不合格代码
     *
     * @param ncGroupBo
     * @return
     */
    public List<Map<String,Object>> findNCGroupMember( String ncGroupBo ){
        Assert.hasText( ncGroupBo, I18nUtil.getI18nText( "common.ncGroupNotBlank" ) );

        return ncGroupAdviceMapper.selectNCGroupMember( ncGroupBo );
    }

    /**
     * 查询在工序有效不合格组
     *
     * @param site
     * @param operation
     * @return
     */
    public List<String> findNCGroupValidOper( String site, String operation ){
        Assert.hasText( operation, I18nUtil.getI18nText( "common.operationNotBlank" ) );

        String operationBo = BOHandleUtil.buildOperationHandleCurrRev( site, operation );
        return ncGroupAdviceMapper.selectNCGroupValidOper( operationBo );
    }
}
